package com.ayuan.blog.service.impl;

import org.apache.commons.collections.CollectionUtils;
import org.durcframework.core.expression.ExpressionQuery;
import org.durcframework.core.expression.subexpression.ValueExpression;
import org.durcframework.core.service.CrudService;
import com.ayuan.blog.service.UserService;
import com.ayuan.blog.dao.UserDao;
import com.ayuan.blog.domain.User;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl 
        extends CrudService<User, UserDao> 
        implements UserService {

    @Override
    public User findUserByAccountId(Integer accountId) {
        ExpressionQuery query = new ExpressionQuery();
        query.add(new ValueExpression("account_id", accountId));

        List<User> userList = this.getDao().find(query);

        if (CollectionUtils.isNotEmpty(userList)) {
            return userList.get(0);
        }
        return null;
    }
}